﻿Imports BE.BE

Namespace DAL
    Public Class DAL_Contraparte

        Shared Sub altaContraparte(pContraparte As Contraparte_BE)

            Try

                pContraparte.IdContraparte = Helper_DAL.ObtenerProximoId("contraparte")
                Dim strcomm As String = "insert into contraparte (id_contraparte, id_persona) values " & _
                    "(" & pContraparte.IdContraparte & "," & pContraparte.Id & ")"

                Helper_DAL.ExecuteNonQuery(strcomm)

            Catch ex As Exception
                Throw ex
            End Try

        End Sub

        Shared Sub bajaContraparte(pContraparte As Contraparte_BE)

        End Sub

        Shared Sub modificarContraparte(pContraparte As Contraparte_BE)

        End Sub

        Shared Function listarContrapartes() As List(Of Contraparte_BE)
            Dim mLista As New List(Of Contraparte_BE)
            Dim mds As New DataSet
            Dim strcomm As String = "select c.id_contraparte, c.id_persona, p.nombre, p.apellido, p.dni, p.fecha_nacimiento " & _
                " from contraparte c inner join persona p on c.id_persona = p.id_persona"


            Try
                mds = Helper_DAL.ExecuteDataset(strcomm)

                If mds.Tables(0).Rows.Count > 0 Then

                    For Each dr As DataRow In mds.Tables(0).Rows
                        Dim mContra As New Contraparte_BE

                        mContra.IdContraparte = dr.Item(0)
                        mContra.Id = dr.Item(1)
                        mContra.Nombre = dr.Item(2).ToString
                        mContra.Apellido = dr.Item(3).ToString
                        mContra.DNI = dr.Item(4)
                        mContra.FechaNacimiento = dr.Item(5).ToString

                        mLista.Add(mContra)
                    Next



                End If

                Return mLista
            Catch ex As Exception
                Throw ex
            End Try

        End Function



    End Class
End Namespace

